import Vue from 'vue'
import '@/styles/index.scss' // global css

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.min.css'

import App from './App'
import store from './store'
import router from './router'

import Utils from '@/utils/index.js' // 自定义公共js,包含全局变量公共方法
import * as filters from './filters' // global filters

import '@/permission' // permission control

// 设置element-ui
Vue.use(ElementUI)
// 全局公共方法注册
Vue.prototype.Utils = Utils
// 全局过滤器注册
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

// 注册一个全局自定义指令 `v-p`,用于控制权限按钮的显示隐藏,类似v-if
Vue.directive('p', {
  inserted(el, binding, vnode) {
    // console.log(store.getters.subsystemMenuMarkList)

    const subsystemMenuMarkList = JSON.parse(sessionStorage.getItem('subsystemMenuMarkList'))

    if (subsystemMenuMarkList && subsystemMenuMarkList.length) {
      const hasPermission = subsystemMenuMarkList.includes(binding.value)

      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
